home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 6 / 3dlib.zip / 3D.H next >
Text File  |  1988-02-28  |  3KB  |  93 lines

  1. /*  3-D graphics library data structures and prototypes.
  2.     These functions are based on information in
  3.     "Principles of Interactive Computer Graphics", by
  4.     Newman and Sproull, Second Edition, McGraw-Hill,
  5.     Publishers.
  6. */
  7.  
  8. #define    CMAX    4    /* maximum column (4 x 4 matrix) */
  9. #define    RMAX    4    /* maximum row    (4 x 4 matrix) */
  10. #define    DIM     3    /* number of dimensions */
  11.  
  12. typedef double MATRIX [RMAX] [CMAX];
  13.  
  14. /* A MATRIX is used to describe a transformation from one coordinate
  15. system to another.  Multiple transformations may be concatenated by
  16. multiplying their transformation matrices. */
  17.  
  18. typedef double VECTOR [DIM];
  19.  
  20. /* A VECTOR is an array of three coordinates [x,y,z] representing magnitude
  21. and direction.  It is typically used to represent the direction of a
  22. light source, or the normal of a plane. */
  23.  
  24. typedef struct vertex {
  25.     double coord [DIM];
  26.     struct vertex *next;
  27. }VERTEX;
  28.  
  29. typedef struct corner {
  30.     VERTEX *this;
  31.     struct corner *next;
  32. }CORNER;
  33.  
  34. typedef struct face {
  35.     CORNER *first;
  36.     struct face *next;
  37. }FACE;
  38.  
  39. /* A FACE is a plane figure consisting of a linked list of corners.
  40. The corners in the list are assumed to be in clockwise order as viewed
  41. from the outside of an object. */
  42.  
  43. typedef struct object {
  44.     FACE *faces;
  45.     VERTEX *vertices;
  46. } OBJECT;
  47.  
  48. /* An OBJECT is a solid consisting of faces and vertices.  The topology
  49. is completely described by the list of faces; the geometry is described
  50. by the faces and vertices. */
  51.  
  52. /* Initialization functions */
  53.  
  54. void    identity (MATRIX this_mat);
  55. int     new_face (FACE *this_face);
  56. int     new_obj (OBJECT *this_obj);
  57.  
  58. /* Vector and matrix math functions */
  59.  
  60. double  dot_prod (VECTOR vec1, VECTOR vec2);
  61. void    mat_mul (MATRIX mat1, MATRIX mat2, MATRIX prod);
  62. int     normal (FACE *this_face, VECTOR norm);
  63. void    vec_mul (VERTEX *this_vec, MATRIX this_mat, VERTEX *prod);
  64.  
  65. /* Transformation functions */
  66.  
  67. void    scale (double sx, double sy, double sz, MATRIX this_mat);
  68. void    trans (double tx, double ty, double tz, MATRIX this_mat);
  69. void    xrot (double theta, MATRIX this_mat);
  70. void    yrot (double theta, MATRIX this_mat);
  71. void    zrot (double theta, MATRIX this_mat);
  72. void    persp (double s, double d, double f, MATRIX this_mat);
  73.  
  74. /* Put figures on the screen */
  75.  
  76. void    disp_face (VECTOR lsource, int color, FACE *this_face, MATRIX xfrm_mat);
  77. void    disp_object (VECTOR lsource, int color, OBJECT *this_obj, MATRIX xfrm_mat);
  78.  
  79. /* Manipulate data structures */
  80.  
  81. int     add_corner (double x, double y, double z, FACE *this_face);
  82. int     xform (OBJECT this_obj, MATRIX transform);
  83. int     del_face (OBJECT *this_obj, FACE *this_face);
  84. double  max_z (FACE this_face);
  85. double  min_z (FACE this_face);
  86. int     add_face (OBJECT *this_obj, FACE *this_face);
  87.  
  88. /* Dump data structures to screen */
  89.  
  90. void    dump_mat (MATRIX this_mat);
  91. void    dump_vec (VERTEX this_vec);
  92. void    dump_face (FACE this_face);
  93. void    dump_obj (OBJECT this_obj);